
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[EBAS_SP_SIKKERHED_VERIFICER_SESSION]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[EBAS_SP_SIKKERHED_VERIFICER_SESSION]
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE [DBO].[EBAS_SP_SIKKERHED_VERIFICER_SESSION] 
	@session varchar(255)
WITH ENCRYPTION	
AS
	DECLARE 
		@result int,
		@rettighed int
		
	SET NOCOUNT ON		

	IF exists(	SELECT 1 FROM EBAS_SIKKERHED_SESSION
			WHERE GUID = @session
			AND DEAKTIVERET = 0
			AND SLUT_DATO > getDate() )
	BEGIN			
		SET @rettighed = (SELECT EBAS.DBO.EBAS_F_SIKKERHED_HENT_RETTIGHED (@session, getdate()))		
		IF 0 < @rettighed
		BEGIN
			-- Timeout is 15 minutes, period.
			UPDATE EBAS_SIKKERHED_SESSION 
			SET SLUT_DATO = DATEADD(minute, 15, getdate())
			WHERE GUID = @session		
		END
	END
	ELSE
	BEGIN
		SET @rettighed = 0
		DELETE FROM EBAS_SIKKERHED_SESSION WHERE GUID = @session		
	END
	
	SET @result = @rettighed	
	SELECT @result	
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
